<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // let arr = [1, 2, 3, [4, 5, 6],
        //     [7, [8, 9]], 10
        // ];
        // let newArr = [];

        // function clone(arr, newArr) {
        //     for (let i = 0; i < arr.length; i++) {
        //         if (arr[i] instanceof Array) {
        //             newArr[i] = [];
        //             clone(arr[i], newArr[i])
        //         } else {
        //             newArr.push(arr[i]);
        //         }
        //     }
        // }

        // function clone(arr, newArr) {
        //     for (let item of arr) {
        //         if (Array.isArray(item)) {
        //             let temp = [];
        //             clone(item, temp);
        //             newArr.push(temp)
        //         } else {
        //             newArr.push(item)
        //         }
        //     }
        // }
        // clone(arr, newArr);
        // arr[4][1][0] = 'abc'
        // console.log(newArr[4][1][0]);
        // console.log(arr[4][1][0]);


        let obj = {
            name: 'zhangsan',
            age: 18,
            girlfinend: {
                name: "angele baober"
            }
        }
        let newObj = {};

        function cloneObj(obj, newObj) {
            for (let key in obj) {
                if (obj[key] instanceof Object) {
                    newObj[key] = {};
                    cloneObj(obj[key], newObj[key])
                } else {
                    newObj[key] = obj[key]
                }
            }
        }
        cloneObj(obj, newObj);
        obj.girlfinend.name = 'abc'
        console.log(obj);
        console.log(newObj);
    </script>
</body>

</html>